package com.sw.chinesewriteboard.activity;

import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;

import android.app.LocalActivityManager;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;

import com.gyf.barlibrary.ImmersionBar;
import com.sw.chinesewriteboard.R;
import com.sw.chinesewriteboard.config.ChineseDataConfig;
import com.sw.chinesewriteboard.copybook.ZhCopybookActivity;
import com.sw.chinesewriteboard.databinding.ActivityLocalBinding;
import com.sw.chinesewriteboard.operation.ChineseDataOperate;

public class LocalActivity extends AppCompatActivity {

    private PopupWindow mPopupWindows;
    ActivityLocalBinding binding;
    protected LocalActivityManager mLocalActivityManager;
    private boolean pop = false;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ImmersionBar.with(this).transparentStatusBar().statusBarDarkFont(true).init();
        binding = ActivityLocalBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        binding.cbIvBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });

        binding.cbTvTitle.setText("拼音字母笔顺贴");
        mLocalActivityManager = new LocalActivityManager(this, true);
            Bundle states = savedInstanceState != null? (Bundle) savedInstanceState.getBundle("STATES_KEY") : null;
        mLocalActivityManager.dispatchCreate(states);
        Intent intent = new Intent(this,ZhSymbolCopybookActivity.class);
        intent.setAction("android.settings.SETTINGS");
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        View v = mLocalActivityManager.startActivity("one", intent).getDecorView();
        binding.frame.removeAllViews();
        binding.frame.addView(v);
        binding.linearXiala.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (pop == false){
                    pop = true;
                    popWindow();
                }else {
                    pop = false;
                    mPopupWindows.dismiss();
                }
            }
        });
    }


    public void popWindow(){
        View contentView = View.inflate(LocalActivity.this, R.layout.xiala_item2,null);
        mPopupWindows = new PopupWindow(contentView);
        mPopupWindows.setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
        mPopupWindows.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
        mPopupWindows.setFocusable(false);
        RelativeLayout rela_zm = contentView.findViewById(R.id.yyzmt);
        RelativeLayout rela_mx = contentView.findViewById(R.id.yymxt);
        RelativeLayout rela_dc = contentView.findViewById(R.id.yydct);
        rela_zm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                binding.cbTvTitle.setText("拼音字母笔顺贴");
                Intent intent = new Intent(LocalActivity.this,ZhSymbolCopybookActivity.class);
                intent.setAction("android.settings.SETTINGS");
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                View v = mLocalActivityManager.startActivity("one", intent).getDecorView();
                binding.frame.removeAllViews();
                binding.frame.addView(v);
                pop = false;
                mPopupWindows.dismiss();
            }
        });

        rela_mx.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                binding.cbTvTitle.setText("看汉字写拼音");
                Intent intent = new Intent(LocalActivity.this,ZhPin2WordCopybookActivity.class);
                intent.setAction("android.settings.SETTINGS");
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                View v = mLocalActivityManager.startActivity("two", intent).getDecorView();
                binding.frame.removeAllViews();
                binding.frame.addView(v);
                pop = false;
                mPopupWindows.dismiss();
            }
        });
        rela_dc.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                binding.cbTvTitle.setText("看拼音写汉字");
                Intent intent = new Intent(LocalActivity.this,ZhWordCopybookActivity.class);
                intent.setAction("android.settings.SETTINGS");
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                View v = mLocalActivityManager.startActivity("three", intent).getDecorView();
                binding.frame.removeAllViews();
                binding.frame.addView(v);
                pop = false;
                mPopupWindows.dismiss();
            }
        });

        mPopupWindows.showAsDropDown(binding.linearXiala);
    }
}